package com.cocos.game;

import android.content.Context;
import android.content.SharedPreferences;

import com.cocos.game.zdkj.model.DeviceLogRecord;

public class MAppCacheManager {
    public static final String SP_FILE_NAME = "MAppCacheManager";

    public static final String COCOS_USER_ID = "cocos_user_id";
    // 例：20240822 , 用户初始化的时间（首次安装的时间）
    public static final String USER_MAX_INIT_TIME = "user_max_init_time";

    public static final String DEVICE_ADID = "device_adid";

    public static final String DEVICE_LOG_RECORD = "device_log_record";
    private static SharedPreferences getSP(){
        return MApplication.instance.getSharedPreferences(MApplication.instance.getPackageName() + SP_FILE_NAME, Context.MODE_PRIVATE);
    }

    public static String getUserId(){
        return getSP().getString(COCOS_USER_ID, "");
    }

    public static void setUserId(String userId){
        getSP().edit().putString(COCOS_USER_ID, userId).apply();
    }

    public static String getUserMaxInitTime(){
        return getSP().getString(USER_MAX_INIT_TIME, "");
    }

    public static void  setUserMaxInitTime(String userMaxInitTime){
        getSP().edit().putString(USER_MAX_INIT_TIME, userMaxInitTime).apply();
    }

    public static String getADID(){
        return getSP().getString(DEVICE_ADID, "");
    }

    public static void setADID(String deviceAdid){
        getSP().edit().putString(DEVICE_ADID, deviceAdid).apply();
    }

    public static DeviceLogRecord getDeviceLogRecord(){
        return ZDKJUtils.gson.fromJson(getSP().getString(DEVICE_LOG_RECORD, "{}"), DeviceLogRecord.class);
    }

    public static void setDeviceLogRecord(DeviceLogRecord deviceLogRecord){
        getSP().edit().putString(DEVICE_LOG_RECORD, ZDKJUtils.gson.toJson(deviceLogRecord)).apply();
    }
}
